package cn.com.api.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.api.entity.ApiU_juhe_region;

import cn.com.api.mapper.ApiU_juhe_regionMapper;

import cn.com.api.service.ApiU_juhe_regionService;
import cn.com.api.service.impl.base.U_juhe_regionServiceImplBase;
import cn.com.util.Util;

/**
 * 
 **/
@Service
public class ApiU_juhe_regionServiceImpl extends U_juhe_regionServiceImplBase implements ApiU_juhe_regionService{
	@Autowired
	private ApiU_juhe_regionMapper apiU_juhe_regionMapper;
    
	
     	//新增对象后返回记录ID
    public int U_juhe_regionInsertion(ApiU_juhe_region u_juhe_region){
        return this.apiU_juhe_regionMapper.U_juhe_regionInsertion(u_juhe_region);
    }
 
    //更新JuHe区域编码
    public int Update_Juhe_Region(List<ApiU_juhe_region> juhe_region_list)
    {
    	int ret = 1;
    	this.apiU_juhe_regionMapper.deleteU_juhe_region();
    	
    	for (ApiU_juhe_region juhe_region : juhe_region_list) 
    	{
			ret = ret * this.apiU_juhe_regionMapper.insertU_juhe_region(juhe_region);
		}
    	
    	return ret;
    }
    
    //获取获取ID
    public String getAreaID(Map map)
    {
    	List<ApiU_juhe_region> region_list = this.apiU_juhe_regionMapper.findU_juhe_regionsByMap(map);
    	if(Util.isNull(region_list) || region_list.size()< 1)
    	{
    		map.remove("area");
    		region_list = this.apiU_juhe_regionMapper.findU_juhe_regionsByMap(map);
    	}
    	if(Util.isNull(region_list) || region_list.size()< 1)
    	{
    		return "101010100";
    	}
    	else {
			return region_list.get(0).getAreaid();
		}
    }
}


